package com.zy.utils

import android.os.Handler
import android.os.HandlerThread
import android.os.Looper

object ThreadUtils {

    private val ioHandlerThread = HandlerThread("zy_io_HandlerThread")

    init {
        ioHandlerThread.start()
    }

    private val ioHandler = Handler(ioHandlerThread.looper)

    private val mainHandler = Handler(Looper.getMainLooper())

    fun ioRun(run: Runnable) {
        ioPostDelayed(0, run)
    }

    fun mainRun(run: Runnable) {
        mainPostDelayed(0, run)
    }

    fun ioPostDelayed(delayed: Long, run: Runnable) {
        ioHandler.postDelayed(run, delayed)
    }

    fun mainPostDelayed(delayed: Long, run: Runnable) {
        mainHandler.postDelayed(run, delayed)
    }

}